// src/models/diary/index.ts

import axios from "@/api";  // 假设你使用 axios 进行 API 请求

// 定义日记接口
export interface Diary {
  id: number;
  title: string;
  content: string;
  createdAt: string;
  updatedAt: string;
  userId: number;
}

// 获取日记列表
export const getDiaryListAPI = () => {
  return axios({
    url: "http://localhost:1314/api/diary", // 使用后端接口的 URL
    method: "get"
  });
};

// 获取单篇日记详情
export const getDiaryDetailAPI = (id: number) => {
  return axios({
    url: `http://localhost:1314/api/diary/${id}`, // 根据 id 获取日记详情
    method: "get"
  });
};

// 创建日记
export const createDiaryAPI = (data: Omit<Diary, 'id' | 'createdAt' | 'updatedAt'>) => {
  return axios({
    url: "http://localhost:1314/api/diary", // 使用后端接口的 URL
    method: "post",
    data
  });
};

// 编辑日记
export const editDiaryAPI = (id: number, data: Omit<Diary, 'id' | 'createdAt' | 'updatedAt'>) => {
  return axios({
    url: `http://localhost:1314/api/diary/${id}`, // 根据 id 编辑日记
    method: "put",
    data
  });
};

// 删除日记
export const deleteDiaryAPI = (id: number) => {
  return axios({
    url: `http://localhost:1314/api/diary/${id}`, // 根据 id 删除日记
    method: "delete"
  });
};
